package net.crowdloud.client.groups;

import net.crowdloud.client.GlobalVariables;
import net.crowdloud.shared.entities.Groups;
import net.crowdloud.shared.utilities.FormField;
import net.crowdloud.shared.utilities.HomeIcon;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * 
 * @UserManual
 */
public class GroupsForm extends VerticalPanel {

	public static final TextArea groupsField = new TextArea();

	public GroupsForm() {

		this.setBorderWidth(1);

		VerticalPanel vp = new VerticalPanel();

		vp.setSpacing(30);

		vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
		vp.add(new HomeIcon());
		vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

		groupsField.setSize("500px", "100px");
		groupsField.setValue(GlobalVariables.groups);
		vp.add(new FormField("Groups", groupsField));

		vp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);

		HorizontalPanel hp = new HorizontalPanel();

		hp.setWidth("300px");

		hp.add(buttonSave());

		vp.add(hp);

		this.add(vp);
	}

	private Button buttonSave() {

		Button button = new Button("Save", new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {

				Groups groups = new Groups();
				groups.setGroups(groupsField.getValue());

				new UpdateGroups(groups);
			}
		});

		return button;
	}

}
